package TankGame;

import java.awt.*;

// 子弹类
class Bullet {
    int x, y; // 子弹坐标
    int speed = 10; // 子弹速度
    double angle; // 子弹飞行角度
    int explosionFrames = 5; // 爆炸帧数
    boolean exploded = false;
    private final boolean isPlayerBullet; // 是否为玩家发射的子弹

    public Bullet(int startX, int startY, double angle, boolean isPlayerBullet) {
        this.x = startX;
        this.y = startY;
        this.angle = angle;
        this.isPlayerBullet = isPlayerBullet;
    }

    public void move() {
        if (!exploded) {
            x += speed * Math.cos(angle);
            y -= speed * Math.sin(angle);
        } else {
            explosionFrames--;
            if (explosionFrames <= 0) {
                exploded = true;
            }
        }
    }

    public void draw(Graphics2D g) {
        if (!exploded) {
            g.setColor(Color.YELLOW);
            g.fillOval(x, y, 10, 10); // 简单绘制一个圆形作为子弹
        } else {
            g.setColor(Color.ORANGE);
            g.fillOval(x - 10, y - 10, 30, 30); // 绘制爆炸效果
        }
    }

    public Rectangle getBounds() {
        return new Rectangle(x, y, 10, 10);
    }

    public boolean isExploded() {
        return exploded;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public boolean isPlayerBullet() { // 添加 getter 方法
        return isPlayerBullet;
    }
}
